iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 29
0
Software Development

開源的GIS實作系列 第 29

[day-29] 串接3

  • 分享至 

  • xImage
  •  

前言

接下來我們有了k-means的分成果,接下來當然是開始計算數量啦!!!計算數量請參考[day-23] opencv - 計算封閉圖形數量(2)

串接計算數量程式

# CountFunc.py

import cv2、
def Count_Plant(count_path):
    img = cv2.imread(count_path)
    dst= img[:,:,0]

    contours, hierarchy = cv2.findContours(dst,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)  #輪廓檢測函數
    count=0  
    for cont in contours:
        count+=1    #總體計數加1
    return count

整合

from ODMFunc import Run_Nodeodm, Catch_Filename
from IMAGEFunc import std_convoluted, add_exif
from KMEANFunc import image_kmeans_classification
from CountFunc import Count_Plant

def main():
    sys.path.append('..')
    upload_file = sys.argv[1] # 將外部參數sys.avgv[1]作為upload檔案輸入。
    filename_list = Catch_Filename(upload_file) # 遍歷upload_file的所有Jpg並且回傳一個list
    Run_Nodeodm(filename_list) # 執行影像建模
    
    img_path = "./results/odm_orthophoto/odm_orthoimage.tif"
    img_output_path = "./results/odm_orthoimage_variance.tif"
    kmeans_image_path = "./results/odm_orthoimage_kmeans.tif"
    
    img = skimage.io.imread(img_path)
    img_g = img[:,:,1]
    N = 3
    img_var = std_convoluted(img_g, N)
    img_var = numpy.asarray(img_var)
    skimage.io.imsave(img_output_path,img_var)
    add_exif(img_output_path,img_path)
    
    image_array = skimage.io.imread(img_output_path)
    image_array_classification = image_kmeans_classification(image_array)
    skimage.io.imsave(img_output_path,kmeans_image_path)
    count = Count_Plant(kmeans_image_path) # 計算秧苗數量
    print(count)

結語

終於串接完成,明天做個30的總結。


上一篇
[day-28] 串接2
下一篇
[day-30] GIS實作總結
系列文
開源的GIS實作30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言